<?php
use yii\helpers\Html;
use yii\widgets\LinkPager;
?>
<?php $this->beginBlock('title'); ?>游戏公告<?php $this->endBlock();?>
<?php $this->beginBlock('breadcrumb'); ?>
<li class="active"><a href="<?php echo \Yii::$app->urlManager->createUrl('/game-notice/index')?>">游戏公告</a></li>
<?php $this->endBlock();?>

<style>
.auto_height { height: 350px; OVERFLOW-Y: auto; SCROLLBAR-FACE-COLOR: #ffffff; }
</style>
<div class="row">
	<div class="col-sm-12">
		<section class="panel">
			<div class="panel-body">
				<form class="form-inline" role="form" action="<?php echo \Yii::$app->urlManager->createUrl('/game-notice/index')?>" method="get">
					<div class="form-group">
						<label class="sr-only" for="key">关键字</label>
                        <input type="text" class="form-control" id="key" name="key" value="<?=\Yii::$app->request->get('key');?>" placeholder="名称模糊查询">
                    </div>
                    <div class="form-group">
						<select class="form-control" name="gametype">
							<option value="" <?php if(\Yii::$app->request->get('gametype')==""):?>selected<?php endif;?>>--全部状态--</option>
							<option value="0" <?php if(\Yii::$app->request->get('gametype')=="0"):?>selected<?php endif;?>>不关联游戏</option>
							<option value="1" <?php if(\Yii::$app->request->get('gametype')=="1"):?>selected<?php endif;?>>单机</option>
							<option value="2" <?php if(\Yii::$app->request->get('gametype')=="2"):?>selected<?php endif;?>>网游</option>
                    	</select>
                    </div>
					<button type="submit" class="btn btn-info"><i class="fa fa-search"></i> 查询</button>
					<a href="<?php echo \Yii::$app->urlManager->createUrl('/game-notice/edit');?>"><button type="button" class="btn btn-success"><i class="fa fa-plus"></i> 添加游戏公告 </button></a>
				</form>
			</div>
			<table class="table table-hover">
				<thead>
					<tr>
						<th>#&nbsp;&nbsp;<i data-val="<?php echo \Yii::$app->request->get('id');?>" data-sort="id" class="sort fa <?php if(\Yii::$app->request->get('id')=='desc'):?>fa-sort-amount-desc<?php elseif(\Yii::$app->request->get('id')=='asc'):?>fa-sort-amount-asc<?php else:?>fa-arrows-v<?php endif;?>" style="cursor: pointer;"></i></th>
						<th>所属游戏</th>
						<th>标题</th>
						<th>链接</th>
						<th>类型</th>
						<th>排序值 &nbsp;&nbsp;<i data-val="<?php echo \Yii::$app->request->get('orderno');?>" data-sort="orderno" class="sort fa <?php if(\Yii::$app->request->get('orderno')=='desc'):?>fa-sort-amount-desc<?php elseif(\Yii::$app->request->get('orderno')=='asc'):?>fa-sort-amount-asc<?php else:?>fa-arrows-v<?php endif;?>" style="cursor: pointer;"></i></th>
						<th>开始日期</th>
						<th>结束日期</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<?php foreach ($models as $item):?>
					<tr>
						<td><?= $item['id']?></td>
						<td><?= truncate(Html::encode(!empty($item['game_name'])?$item['game_name']:'尚未指派'),12,'..');?></td>
						<td><?= truncate(Html::encode($item['title']),15);?></td>
						<td><?= truncate(Html::encode($item['url']),18);?></td>
						<td><?php if($item['showchannel']==0){echo '全部';}elseif ($item['showchannel']==1){echo '安卓';}elseif ($item['showchannel']==2){echo 'IOS';}else{echo '未知';}?></td>
						<td><?= $item['orderno']?></td>
						<td><?= date('Y-m-d',$item['starttime']);?></td>
						<td><?= date('Y-m-d',$item['endtime']);?></td>
						<td>
							<a class="btn btn-sm btn-success" data-toggle="modal" href="#custModal" onclick="gameAssign(<?=$item['id'];?>,'<?=$item['title'];?>')"><i class="icon-star"></i> 指派游戏</a>
							<a class="btn btn-sm btn-primary" href="<?=\Yii::$app->urlManager->createUrl(['/game-notice/edit','id'=>$item['id']]);?>"><i class="icon-pencil"></i> 编辑</a>
							<a class="btn btn-sm btn-danger" data-toggle="modal" href="#DeleteConfirmModal" onclick="deleteConfirm(<?=$item['id'];?>,'<?=$item['title'];?>')"><i class="icon-trash"></i> 删除</a>
						</td>
					</tr>
					<?php endforeach;?>
				</tbody>
			</table>
			<div class="text-center">
				<?php
                echo LinkPager::widget([
                    'pagination' => $pages,
                ]);
                ?>
			</div>
		</section>
	</div>
</div>

<!-- Modal -->
<div class="modal fade" id="DeleteConfirmModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">删除确认</h4>
            </div>
            <div class="modal-body">
                <p>您确定要删除“<strong id="game_notice_title"></strong>”此游戏公告吗？</p>
            </div>
            <div class="modal-footer">
            	<form method="post" action="<?php echo \Yii::$app->urlManager->createUrl('/game-notice/delete');?>">
            	   <input type="hidden" name="_csrf" id="_csrf" value="<?=\Yii::$app->request->csrfToken; ?>" />
	            	<input type="hidden" id="notice_id" name="notice_id" value="" >
	                <button class="btn btn-danger" type="submit"> 确认</button>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- modal -->

<!-- Modal -->
<div class="modal fade" id="custModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">对公告指派所属游戏</h4>
            </div>
            <div class="modal-body">
            	接下来您将给“<STRONG id="game_notice_title2"></STRONG>”指派所属的游戏，可使用搜索查找
            	<div class="row">
	                <div class="col-sm-12">
						<section class="panel">
							<div class="panel-body">
								<form class="form-inline" role="form" id="game_search_form">
									<div class="form-group">
										<label class="sr-only" for="key">关键字</label>
				                        <input type="text" class="form-control" id="modal_key" name="modal_key" value="" placeholder="游戏名称">
				                    </div>
				                    <div class="form-group">
				                    	<select class="form-control" name="state_id">
											<option value="" <?php if(\Yii::$app->request->get('state_id')!=''):?>selected<?php endif;?>>--所有状态--</option>
                                            <?php foreach($states as $item):?>
                								<option value="<?=$item['state_id'];?>" <?php if($item['state_id']==\Yii::$app->request->get('state_id')):?>selected<?php endif;?>><?=$item['state_name'];?></option>
                							<?php endforeach;?>
										</select>
				                    </div>
				                    <INPUT type="hidden" value="" name="game_notice_id" id="game_notice_id" />
									<button type="button" class="btn btn-info" id="GameFind"><i class="fa fa-search"></i> 查询</button>
								</form>
							</div>
							<div id="GameList">

							</div>
						</section>
					</div>
				</div>
            </div>
            <div class="modal-footer">
                <button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
            </div>
        </div>
    </div>
</div>
<!-- modal -->

<?php $this->beginBlock('script'); ?>
<script type="text/javascript">
//删除确认
function deleteConfirm(id, title){
	$("#notice_id").val(id);
	$("#game_notice_title").text(title);
}

//排序
$(".sort").click(function() {
    var url = "<?php echo \Yii::$app->urlManager->createUrl(['/game-notice/index','page' => \Yii::$app->request->get('page'), 'key' => \Yii::$app->request->get('key',''), 'gametype' => \Yii::$app->request->get('gametype','')])?>";
    var val = $(this).attr('data-val');
    var sort = $(this).attr('data-sort');
    if (val != 'desc') {
        url += '&'+sort+'=desc';
    } else {
        url += '&'+sort+'=asc';
    }
    window.location.href = url;
});

//游戏指派
function gameAssign(id, title){
	$("#game_notice_id").val(id);
	$("#game_notice_title2").text(title);
}

//游戏模态框的搜索
$("#GameFind").click(function() {
    $.get("<?php echo \Yii::$app->urlManager->createUrl('/game/search-by-notice');?>", $("#game_search_form").serialize(), function(data) {
        $("#GameList").html(data);
    },'html');
    $("#GameList").addClass("auto_height");
});
</script>
<?php $this->endBlock('script'); ?>